//
//  BSImageManager.m
//  BaiSi
//
//  Created by Sycamore on 16/5/3.
//  Copyright © 2016年 Sycamore. All rights reserved.
//
#import "BSImageManager.h"
#import "UIImage+Resize.h"

@implementation BSImageManager

+ (void)bs_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder imageView:(UIImageView *)imageView completed:(SDWebImageCompletionBlock)completedBlock
{
    UIImage *cacheImage = [[SDImageCache sharedImageCache]imageFromDiskCacheForKey:url.absoluteString];
    if (cacheImage) {
        imageView.image = cacheImage;
    }
    else{
        [imageView sd_setImageWithURL:url placeholderImage:placeholder completed:completedBlock];
    }

}


+ (void)bs_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options imageView:(UIImageView *)imageView progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock

{
    UIImage *cacheImage = [[SDImageCache sharedImageCache]imageFromDiskCacheForKey:url.absoluteString];
    if (cacheImage) {
        imageView.image = cacheImage;
    }
    else{
        [imageView sd_setImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:completedBlock];
    }

    
}


+ (UIImage *)setHeaderImageWithURL:(NSURL *)url placeholder:(NSString *)placeholder inImageView:(UIImageView *)iconView
{
    
    UIImage *headerImage = [[SDImageCache sharedImageCache]imageFromDiskCacheForKey:url.absoluteString];
    if (headerImage) {
        //切成圆框图片
        headerImage = [UIImage clipRoundImage:headerImage];
        iconView.image = headerImage;
    }
    else{
        headerImage = [UIImage clipRoundImage:[UIImage imageNamed:placeholder]];
        iconView.image = headerImage;
        
    }
    
    return headerImage;
    
}


@end
